package shortcircuit.graphics;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.RescaleOp;
import java.util.ArrayList;

import javax.swing.JLabel;
import javax.swing.JPanel;

import shortcircuit.Display;
import shortcircuit.GameEngine;
import shortcircuit.engine.PuzzleEngine;

/**
 * This PopUpScreen is displayed at the beginning of a new mode.  In Puzzle Mode, the current
 * Level is displayed.  In Endless Mode, a countdown is initiated before the gameplay begins.
 * @author Kevin Lewi
 *
 */
public class BeginGameScreen extends PopUpScreen
{	
	
	public BeginGameScreen(int typeOfGame, GameEngine theEngine)
	{
		super(typeOfGame, theEngine);
		_Transparency = 1.0f;
	}



	public void paint(Graphics g)
	{
		if(beginFading)
		{
			fadeOut(g);
		}
		else if(theAnimator != null)
		{
			switch(typeOfGame)
			{
			case 0:
				_Engine.statsScreen.update(); //causes strange nullpointer to be thrown
				_Transparency = 2.0f;
				ArrayList<Image> theImages = Display.generateImages(((PuzzleEngine) _Engine).getLevel());
				Image[] tempArray = new Image[theImages.size() + 1];
				for(int i = 0; i < tempArray.length; i++)
				{
					if(i == 0)
						tempArray[i] = Display.levelImage;
					else
						tempArray[i] = theImages.get(i - 1);
				}
				initiateFader(tempArray);
				break;
			case 1:
				switch(stepCounter % 4)
				{
				case 0:
					_Engine.statsScreen.update(); //causes strange nullpointer to be thrown
					g.drawImage(Display.readyImage, 0, 0, this);
					g.drawImage(Display.numberImages[3], NUMBER_IMAGE_OFFSET + 10, 0, this);
					break;
				case 1:
					g.drawImage(Display.readyImage, 0, 0, this);
					g.drawImage(Display.numberImages[2], NUMBER_IMAGE_OFFSET + 10, 0, this);
					break;
				case 2:
					g.drawImage(Display.readyImage, 0, 0, this);
					g.drawImage(Display.numberImages[1], NUMBER_IMAGE_OFFSET + 10, 0, this);
					break;
				case 3:
					g.drawImage(Display.goImage, 0, 0, this);
					_Transparency = 3.0f;
					Image[] tempArray2 = {Display.goImage};
					initiateFader(tempArray2);
					break;
				}
				break;
			case 2:
				doneLoading = true;
				break;
			}
		}
	}


}
